<?

/********************************************
* team.php
*
* This page displays information about a team
*
********************************************/

//include files
include "config.php";
include "../lib/db.php";
include "../lib/tbatv_lib.php";

$tba = new tbatvController();

$year = sanatizeGet($_GET['year']);
if (is_null($year) OR !is_numeric($year)) $year = date('Y');
$teamnumber = sanatizeGet($_GET['team']);
$teamnumber = floor(stripslashes($teamnumber));

//get passed arguments
if (!isset($teamnumber)) {
	$iserror = 1;
	$errorstring = $errorstring + "No team specified.<br />";
	$teamnumber = 0;
} else {
	if ($teaminfo == 0) {
		$error_page = "<h1>Team Number " . $teamnumber . " does not exist.</h1>";
		$error_page = $error_page . "<p>We have no information on team number " . $teamnumber . ". They likely do not exist.</p>";
	}
	
	//look up team information
	$team = new Team($teamnumber);
}

$title = $team->getFullInformalName();

include "header.php";

//Get More Team Info
//look up the matches by the team
$list_of_events = $team->getEvents($year);

?>
<h1><? echo $team->getFullInformalName() ?></h1>
<table id="team_info">
	<tr><td class="title_td">Formal Team Name</td><td><? echo $team->getName() ?></td></tr>
	<tr><td class="title_td">Location</td><td><? echo $tba->buildLocation($team->getCity(), $team->getState(), $team->getCountry()) ?></td></tr>
	<tr><td class="title_td">Rookie Year</td><td><? echo $team->getRookieYear() ?></td></tr>
	<tr><td class="title_td">Official Events Attended in <?echo $year?></td><td><?echo count($list_of_events) ?></td></tr>
	<tr><td class="title_td">Record at Official Events in <?echo $year?></td><td><strong> <?echo $tba->stringWLT($team->getWLT("year", $year)) ?></td></tr>
</table>
<? 
include "views/mobile_robot_thumb.php";
?>

<?
include "views/mobile_listofevents.php"; 

/*//look up if team played in other years.
$historic_event_query_filter = "SELECT DISTINCT events.year FROM events, attendance WHERE attendance.event=events.eventid AND attendance.team = '$teamnumber' AND events.year != '$year' ORDER BY events.year DESC";
$historic_event_query = mysql_query($historic_event_query_filter);

if (mysql_num_rows($historic_event_query) > 0) {
	
	?>
	<h1>Other Matches</h1>
	<p>To view Team <?echo $teamnumber?>'s other matches, please select a different year:</p>
	<ul>
	<?
	while($t=mysql_fetch_array($historic_event_query)) {
	 echo "<li><a href=\"?team=$teamnumber&year={$t["year"]}\">{$t["year"]}</a></li>";
	}
	?>
	</ul>
	
	<?
}
*/
?>

</div> <?
include "footer.php";
?>